package com.cn.goodsadmin.common.Lock;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by fly on 17/5/26.
 */
public class CountLock {

    private AtomicInteger count;

    public CountLock(int number){
        count=new AtomicInteger(number);
    }

    public CountLock(){
        count=new AtomicInteger();
    }

    public void  set(int number){
        count.set(number);
    }

    public void increment() {
        count.incrementAndGet();
    }

    //使用AtomicInteger之后，不需要加锁，也可以实现线程安全。
    public int getCount() {
        return count.addAndGet(1);
    }
}
